package 集合框架.kgc.课后作业.M2;

import java.util.Objects;

public class Employee {
    private int nameIdl; //员工id
    private String name;//员工姓名
    private int age;  //员工年龄
    private int YSd; //员工工资

    public Employee() {
    }

    public Employee(int nameIdl, String name, int age, int YSd) {
        this.nameIdl = nameIdl;
        this.name = name;
        this.age = age;
        this.YSd = YSd;
    }

    public int getNameIdl() {
        return nameIdl;
    }

    public void setNameIdl(int nameIdl) {
        this.nameIdl = nameIdl;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getYSd() {
        return YSd;
    }

    public void setYSd(int YSd) {
        this.YSd = YSd;
    }

    @Override
    /**
     * 为Employee 类重写equals方法和hashCode()方法，当员工工号、员工姓名相等时候才返回true
     */
    public boolean equals(Object o) {
        Employee employee = (Employee) o;
        if (this.getNameIdl() == employee.nameIdl && this.getName().equals(employee.getName()))
            return true;
        else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        return Objects.hash(nameIdl, name, age, YSd);
    }

    @Override
    public String toString() {
        return "Employee{" +
                "nameIdl=" + nameIdl +
                ", name='" + name + '\'' +
                ", age=" + age +
                ", YSd=" + YSd +
                '}';
    }

    public void work() {
        System.out.println(toString() + "工人正在工作中.......");
    }
}
